/* Export Protocol for Sectors
 * JSON Representation of the Sector.
 */

ImportModules["Current"] = {};

ImportModules["Current"].ExportSector = function(sector)
{
  var buildings = [];
  var planets = [];
  var starbases = [];
  var backgrounds = [];

  for (var i = 0; i < sector.buildings.length; i++)
  {
    var building = sector.buildings[i];
    buildings.push({ id: building.id,
      name: building.name,
      owner: building.owner,
      level: building.level
    });
  }

  for (var i = 0; i < sector.planets.length; i++)
  {
    var planet = sector.planets[i];
    planets.push({ id: planet.id,
      type: planet.type,
      population: planet.population
    });
  }

  for (var i = 0; i < sector.starbases.length; i++)
  {
    var starbase = sector.starbases[i];
    starbases.push({ id: starbase.id,
      owner: starbase.owner,
      population: starbase.population
    });
  }

  for (var i = 0; i < sector.backgrounds.length; i++)
  {
    var background = sector.backgrounds[i];
    backgrounds.push({ id: background.id,
      image: background.image
    });
  }

  return JSON.encode({
    version: ProtocolVersion,
    name: sector.name,
    map: sector.map,
    buildings: buildings,
    planets: planets,
    starbases: starbases,
    backgrounds: backgrounds
  });
}

ImportModules["Current"].ExportPricelist = function(pricelist)
{
  pricelist["version"] = ProtocolVersion;
  return JSON.encode(pricelist);
}